﻿using Kavaa.Core.Data;
using Kavaa.Modules.PortailMedical.Entity;
using System;
using System.Data.SqlClient;
using Kavaa.Core.Tracing;
using System.Collections;
using System.Collections.Generic;


namespace Kavaa.Modules.PortailMedical.Datalayer
{
    internal static class CliniqueDAO
    {
        [ThreadStatic()]
        private static TraceInfo traceInfo;
        public static TraceInfo TraceInfo
        {
            get
            {
                if (traceInfo == null)
                    traceInfo = new TraceInfo(typeof(PortailMedicalDao));
                return traceInfo;
            }
        }
        public static Cliniques GetCliniques()
        {
            throw new Exception("A impélmenter");
        }

        public static Cliniques DecouvrirCliniques(int acteId, int villeId)
        {
            TraceInfo.WriteVerbose("Entrée dans la méthode {0} de la classe statique {1} (NameSpace {2}", "GetCliniquesByActeByVille", "PortailMedicalDao", "Kavaa.Modules.AssIsTSync.Datalayer");
            Cliniques cliniques = new Cliniques();

            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetCliniquesByActeByVille]"
            , new List<SqlParameter>() { 
                new SqlParameter("@acteId", acteId),
                new SqlParameter("@villeId", villeId),
            }))
            {
                cliniques.Add(new Clinique()
                {
                    Id = (row["CliniqueId"] != DBNull.Value) ? Convert.ToInt32(row["CliniqueId"]) : 0,
                    Name = (row["CliniqueName"] != DBNull.Value) ? Convert.ToString(row["CliniqueName"]) : null,
                    Adresse = (row["CliniqueAdresse"] != DBNull.Value) ? Convert.ToString(row["CliniqueAdresse"]) : null,
                    Tel = (row["CliniqueTelephone"] != DBNull.Value) ? Convert.ToString(row["CliniqueTelephone"]) : null,
                    Email = (row["CliniqueEmail"] != DBNull.Value) ? Convert.ToString(row["CliniqueEmail"]) : null,
                    srcMap = (row["CliniqueMap"] != DBNull.Value) ? Convert.ToString(row["CliniqueMap"]) : null,
                });
            }

            TraceInfo.WriteVerbose("Fin de la méthode {0} de la classe statique {1} (NameSpace {2}", "GetCliniquesByActeByVille", "PortailMedicalDao", "Kavaa.Modules.AssIsTSync.Datalayer");
            return cliniques;
        }

        public static Cliniques DecouvrirCliniquesByActe(int acteId)
        {
            Cliniques cliniques = new Cliniques();

            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetCliniquesByActe]"
            , new List<SqlParameter>() { 
                new SqlParameter("@acteId", acteId),
               
            }))
            {
                cliniques.Add(new Clinique()
                {
                    Id = (row["CliniqueId"] != DBNull.Value) ? Convert.ToInt32(row["CliniqueId"]) : 0,
                    Name = (row["CliniqueName"] != DBNull.Value) ? Convert.ToString(row["CliniqueName"]) : null,
                    Adresse = (row["CliniqueAdresse"] != DBNull.Value) ? Convert.ToString(row["CliniqueAdresse"]) : null,
                    Tel = (row["CliniqueTelephone"] != DBNull.Value) ? Convert.ToString(row["CliniqueTelephone"]) : null,
                    Email = (row["CliniqueEmail"] != DBNull.Value) ? Convert.ToString(row["CliniqueEmail"]) : null,
                    Ville = new Ville() { Name = (row["Ville"] != DBNull.Value) ? Convert.ToString(row["Ville"]) : null },

                });
            }

            TraceInfo.WriteVerbose("Fin de la méthode {0} de la classe statique {1} (NameSpace {2}", "GetCliniquesByActeByVille", "PortailMedicalDao", "Kavaa.Modules.AssIsTSync.Datalayer");
            return cliniques;
        }

        public static int SaveRessourceClinique(int RessourceId, int CliniqueId)
        {
            int ID = 0;
            foreach (var row in

            SqlDaoAdapter.ExecuteReader(ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_SaveRessourceClinique]"
            , new List<SqlParameter>() { 
                new SqlParameter("@RessourceId", RessourceId),
                new SqlParameter("@CliniqueId", CliniqueId)
               
               
            }))
            { ID = (row["ID"] != DBNull.Value) ? Convert.ToInt32(row["ID"]) : 0; }

            return ID;
        }
    }
}
